package hash_1114;


import java.util.Objects;

public class Student {
    private int id;         // 学号
    private String name;    // 姓名

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return String.format("(%d - %s)", id, name);
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public static void main(String[] args) {
        Student s1 = new Student(1, "小A");
        Student s2 = new Student(1, "小A");

        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());
    }
}

